home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / srctab.c < prev    next >
C/C++ Source or Header  |  2002-12-18  |  787b  |  36 lines

  1. #include "srctab.h"
  2. #include "hash.h"
  3.  
  4. #define SRCHSIZE       59
  5.  
  6. static unsigned src_hash_fun( const void *data )
  7. {
  8.     return (unsigned)(((const struct sourcefile*)data)->fname);
  9. }
  10.  
  11. static int src_hash_compare( const void *data1, const void *data2 )
  12. {
  13.     int name1, name2;
  14.     name1 = ((const struct sourcefile*)data1)->fname;
  15.     name2 = ((const struct sourcefile*)data2)->fname;
  16.     return name1-name2;
  17. }
  18.  
  19. static struct hash *srctab = 0;
  20.  
  21. int regsrc( struct sourcefile *sf )
  22. {
  23.     if ( !srctab ) 
  24.         srctab = new_hash( SRCHSIZE, src_hash_fun, src_hash_compare );
  25.     if ( !srctab ) return -100;
  26.     return h_add( srctab, sf );
  27. }
  28.  
  29. struct sourcefile *findsrc( int fname ) 
  30. {
  31.     struct sourcefile sf;
  32.     sf.fname = fname;
  33.     return (struct sourcefile*)h_get( srctab, &sf );
  34. }
  35.  
  36.